/**
@file
    TableLists.cs
@brief
    Copyright 2009 Creative Crew. All rights reserved.
@author
    William Chang
@version
    0.1
@date
    - Created: 2008-08-29
    - Modified: 2009-04-07
    .
@note
    References:
    - General:
        - http://en.wikipedia.org/wiki/C_Sharp_(programming_language)
        .
    .
*/

using System;
using System.Data;
using System.Collections.Generic;
using System.Web;

namespace ent {

/// <summary>Class TableLists extends TableCommon</summary>
public class TableLists : TableCommon {

#region Enumerations

    public enum enumList {
        UserRoles = 1,
        ContentTypes = 2,
        ContentStatuses = 3,
        ContentOrderTypes = 4,
        FileTypes = 5
    }
    public enum enumContentAssignedTo {
        Authors = -2,
        Administrators = -1,
        Moderators = 0
    }
    public enum enumContentOrderType {
        Default = 1,
        DatePublishedAsc = 2,
        DateModifiedAsc = 3,
        DateCreatedAsc = 4,
        HeaderAsc = 5
    }
    public enum enumContentStatus {
        Publish = 1,
        PendingReview = 2,
        Draft = 3
    }
    public enum enumContentType {
        Page = 1,
        Blog = 2,
        Post = 3,
        Template = 4,
        Style = 5,
        System = 6,
        Revision = 7
    }

#endregion

#region Fields

    public const String TBL__lists = "lists";
    public const String TBL__lists___PK = "list_id";
    public const String TBL__lists__list_id = "list_id";
    public const String TBL__lists__list_type = "list_type";
    public const String TBL__lists__list_category_id = "list_category_id";
    public const String TBL__lists__list_symbol = "list_symbol";
    public const String TBL__lists__list_name = "list_name";
    public const String TBL__lists__list_value = "list_value";
    public const String TBL__lists__list_description = "list_description";
    public const String TBL__lists__list_parent_id = "list_parent_id";
    public const String TBL__lists__list_order = "list_order";
    public const String TBL__lists__list_deleted = "list_deleted";

#endregion

    /// <summary>Default constructor.</summary>
	public TableLists() {}
    /// <summary>Get relevant columns for user.</summary>
    public static System.Collections.SortedList getColumnsRelevantList() {
        System.Collections.SortedList p = new System.Collections.SortedList();

        p.Add(1, TBL__lists__list_id);
        p.Add(4, TBL__lists__list_symbol);
        p.Add(5, TBL__lists__list_name);
        p.Add(6, TBL__lists__list_value);
        p.Add(7, TBL__lists__list_order);
        p.Add(8, TBL__lists__list_deleted);
        return p;
    }

#region Stored Procedures: Categories

    /// <summary>Get (SELECT) database item using stored procedure.</summary>
    public DataRow getCategory(System.Collections.Hashtable parameters) {
        return ((DataTable)runStoredProcedure("spSelectListCategories", parameters, DatabaseCommon.enumSqlDataReturn.DataTable)).Rows[0];
    }
    /// <summary>Get (SELECT) database item using stored procedure.</summary>
    public DataTable getCategories(System.Collections.Hashtable parameters) {
        return (DataTable)runStoredProcedure("spSelectListCategories", parameters, DatabaseCommon.enumSqlDataReturn.DataTable);
    }

#endregion

#region Dynamic SQL

    /// <summary>Get item from list by id.</summary>
    public DataRow getItem(int idItem) {
        return base.dynamicSqlSelect(null, TableLists.TBL__lists, TableLists.TBL__lists___PK + " = " + idItem).Rows[0];
    }
    /// <summary>Get name from list by category and value.</summary>
    public String getItemName(int idCategory, int value) {
        System.Collections.Hashtable p1 = new System.Collections.Hashtable();
        p1.Add(TableLists.TBL__lists__list_name, null);
        return (String)base.dynamicSqlSelect(p1, TableLists.TBL__lists, TableLists.TBL__lists__list_value + " = " + value + " AND " + TableLists.TBL__lists__list_category_id + " = " + idCategory).Rows[0][TableLists.TBL__lists__list_name];
    }
    /// <summary>Get list.</summary>
    public DataTable getList(int idCategory, System.Collections.IDictionary parameters) {
        return base.dynamicSqlSelect(parameters, TableLists.TBL__lists, TableLists.TBL__lists__list_deleted + " = 0" + " AND " + TableLists.TBL__lists__list_category_id + " = " + idCategory);
    }
    /// <summary>Get trashed list.</summary>
    public DataTable getListTrashed(int idCategory, System.Collections.IDictionary parameters) {
        return base.dynamicSqlSelect(parameters, TableLists.TBL__lists, TableLists.TBL__lists__list_deleted + " = 1" + " AND " + TableLists.TBL__lists__list_category_id + " = " + idCategory);
    }
    /// <summary>Remove list.</summary>
    public bool removeItem(int idItem) {
        return base.dynamicSqlDelete(TableLists.TBL__lists, TableLists.TBL__lists___PK + " = " + idItem);
    }
    /// <summary>Restore trashed list.</summary>
    public bool restoreItem(int idItem) {
        System.Collections.Hashtable p1 = new System.Collections.Hashtable();
        p1.Add(TableLists.TBL__lists__list_deleted, 0);
        return base.dynamicSqlUpdate(p1, TableLists.TBL__lists, TableLists.TBL__lists___PK + " = " + idItem);
    }
    /// <summary>Trash list.</summary>
    public bool trashItem(int idItem) {
        System.Collections.Hashtable p1 = new System.Collections.Hashtable();
        p1.Add(TableLists.TBL__lists__list_deleted, 1);
        return base.dynamicSqlUpdate(p1, TableLists.TBL__lists, TableLists.TBL__lists___PK + " = " + idItem);
    }

#endregion

    /// <summary>Get assigned to by converting from role.</summary>
    public static int getAssignedToByRole(System.Web.SessionState.HttpSessionState s) {
        int who = -1000;
        switch(ApplicationCommon.getRole(s)) {
            case ApplicationCommon.enumRole.Administrator:
                who = (int)TableLists.enumContentAssignedTo.Administrators;
                break;
            case ApplicationCommon.enumRole.Moderator:
                who = (int)TableLists.enumContentAssignedTo.Moderators;
                break;
            case ApplicationCommon.enumRole.Author:
                who = (int)TableLists.enumContentAssignedTo.Authors;
                break;
            default:
                who = -1000;
                break;
        }
        return who;
    }
    /// <summary>Get role by converting from assigned to.</summary>
    public static ApplicationCommon.enumRole getRoleByAssignedTo(int value) {
        switch(value) {
            case (int)TableLists.enumContentAssignedTo.Administrators:
                return ApplicationCommon.enumRole.Administrator;
            case (int)TableLists.enumContentAssignedTo.Moderators:
                return ApplicationCommon.enumRole.Moderator;
            case (int)TableLists.enumContentAssignedTo.Authors:
                return ApplicationCommon.enumRole.Author;
            default:
                return ApplicationCommon.enumRole.Guest;
        }
    }
}

} // END namespace ent